package com.sport.ui.home;

//import android.app.Fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

//import androidx.fragment.app.Fragment; 不用这个，用这个的话Main.java里fragmentTransaction.replace(R.id
// .bottom, bottomFragment);会报错

import com.sport.databinding.BottomLayoutBinding;
import com.sport.pojo.ProductBean;

import java.io.Serializable;
import java.util.List;

import androidx.fragment.app.Fragment;
//import androidx.fragment.app.FragmentManager;
//import androidx.fragment.app.FragmentTransaction;

public class BottomFragment extends Fragment {
    private BottomLayoutBinding binding;
    private GridView gv_list;

    public BottomFragment getInstance(List<ProductBean> list) {
        BottomFragment rightFragment = new BottomFragment();
        //通过Bundle对象传递数据可以保证在设备横竖屏切换时传递的数据不丢失
        Bundle bundle = new Bundle();
        //将需要传递的字符串以键值对的形式传入bundle对象
        bundle.putSerializable("list", (Serializable) list);
        rightFragment.setArguments(bundle);
        return rightFragment;
    }

    @Override

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        binding = BottomLayoutBinding.inflate(inflater, container, false);
        gv_list = binding.gvList;
        if (getArguments() != null) {
            List<ProductBean> list = (List<ProductBean>) getArguments().
                    getSerializable("list");
            BottomAdapter adapter = new BottomAdapter(getActivity(), list);
            gv_list.setAdapter(adapter);
        }
        View view = binding.getRoot();
        return view;
    }

//
}